1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.PaperSize;
26 
27 private import glib.ConstructionException;
28 private import glib.ErrorG;
29 private import glib.GException;
30 private import glib.KeyFile;
31 private import glib.ListG;
32 private import glib.Str;
33 private import glib.Variant;
34 private import glib.c.functions;
35 private import gobject.ObjectG;
36 private import gtk.c.functions;
37 public  import gtk.c.types;
38 private import linker.Loader;
39 
40 
41 /**
42  * `GtkPaperSize` handles paper sizes.
43  * 
44  * It uses the standard called
45  * [PWG 5101.1-2002 PWG: Standard for Media Standardized Names](http://www.pwg.org/standards.html)
46  * to name the paper sizes (and to get the data for the page sizes).
47  * In addition to standard paper sizes, `GtkPaperSize` allows to
48  * construct custom paper sizes with arbitrary dimensions.
49  * 
50  * The `GtkPaperSize` object stores not only the dimensions (width
51  * and height) of a paper size and its name, it also provides
52  * default print margins.
53  */
54 public class PaperSize
55 {
56 	/** the main Gtk struct */
57 	protected GtkPaperSize* gtkPaperSize;
58 	protected bool ownedRef;
59 
60 	/** Get the main Gtk struct */
61 	public GtkPaperSize* getPaperSizeStruct(bool transferOwnership = false)
62 	{
63 		if (transferOwnership)
64 			ownedRef = false;
65 		return gtkPaperSize;
66 	}
67 
68 	/** the main Gtk struct as a void* */
69 	protected void* getStruct()
70 	{
71 		return cast(void*)gtkPaperSize;
72 	}
73 
74 	/**
75 	 * Sets our main struct and passes it to the parent class.
76 	 */
77 	public this (GtkPaperSize* gtkPaperSize, bool ownedRef = false)
78 	{
79 		this.gtkPaperSize = gtkPaperSize;
80 		this.ownedRef = ownedRef;
81 	}
82 
83 	~this ()
84 	{
85 		if ( Linker.isLoaded(LIBRARY_GTK[0]) && ownedRef )
86 			gtk_paper_size_free(gtkPaperSize);
87 	}
88 
89 
90 	/** */
91 	public static GType getType()
92 	{
93 		return gtk_paper_size_get_type();
94 	}
95 
96 	/**
97 	 * Creates a new `GtkPaperSize` object by parsing a
98 	 * [PWG 5101.1-2002](ftp://ftp.pwg.org/pub/pwg/candidates/cs-pwgmsn10-20020226-5101.1.pdf)
99 	 * paper name.
100 	 *
101 	 * If @name is %NULL, the default paper size is returned,
102 	 * see [func@Gtk.PaperSize.get_default].
103 	 *
104 	 * Params:
105 	 *     name = a paper size name
106 	 *
107 	 * Returns: a new `GtkPaperSize`, use [method@Gtk.PaperSize.free]
108 	 *     to free it
109 	 *
110 	 * Throws: ConstructionException GTK+ fails to create the object.
111 	 */
112 	public this(string name)
113 	{
114 		auto __p = gtk_paper_size_new(Str.toStringz(name));
115 
116 		if(__p is null)
117 		{
118 			throw new ConstructionException("null returned by new");
119 		}
120 
121 		this(cast(GtkPaperSize*) __p);
122 	}
123 
124 	/**
125 	 * Creates a new `GtkPaperSize` object with the
126 	 * given parameters.
127 	 *
128 	 * Params:
129 	 *     name = the paper name
130 	 *     displayName = the human-readable name
131 	 *     width = the paper width, in units of @unit
132 	 *     height = the paper height, in units of @unit
133 	 *     unit = the unit for @width and @height. not %GTK_UNIT_NONE.
134 	 *
135 	 * Returns: a new `GtkPaperSize` object, use [method@Gtk.PaperSize.free]
136 	 *     to free it
137 	 *
138 	 * Throws: ConstructionException GTK+ fails to create the object.
139 	 */
140 	public this(string name, string displayName, double width, double height, GtkUnit unit)
141 	{
142 		auto __p = gtk_paper_size_new_custom(Str.toStringz(name), Str.toStringz(displayName), width, height, unit);
143 
144 		if(__p is null)
145 		{
146 			throw new ConstructionException("null returned by new_custom");
147 		}
148 
149 		this(cast(GtkPaperSize*) __p);
150 	}
151 
152 	/**
153 	 * Deserialize a paper size from a `GVariant`.
154 	 *
155 	 * The `GVariant must be in the format produced by
156 	 * [method@Gtk.PaperSize.to_gvariant].
157 	 *
158 	 * Params:
159 	 *     variant = an a{sv} `GVariant`
160 	 *
161 	 * Returns: a new `GtkPaperSize` object
162 	 *
163 	 * Throws: ConstructionException GTK+ fails to create the object.
164 	 */
165 	public this(Variant variant)
166 	{
167 		auto __p = gtk_paper_size_new_from_gvariant((variant is null) ? null : variant.getVariantStruct());
168 
169 		if(__p is null)
170 		{
171 			throw new ConstructionException("null returned by new_from_gvariant");
172 		}
173 
174 		this(cast(GtkPaperSize*) __p);
175 	}
176 
177 	/**
178 	 * Creates a new `GtkPaperSize` object by using
179 	 * IPP information.
180 	 *
181 	 * If @ipp_name is not a recognized paper name,
182 	 * @width and @height are used to
183 	 * construct a custom `GtkPaperSize` object.
184 	 *
185 	 * Params:
186 	 *     ippName = an IPP paper name
187 	 *     width = the paper width, in points
188 	 *     height = the paper height in points
189 	 *
190 	 * Returns: a new `GtkPaperSize`, use [method@Gtk.PaperSize.free]
191 	 *     to free it
192 	 *
193 	 * Throws: ConstructionException GTK+ fails to create the object.
194 	 */
195 	public this(string ippName, double width, double height)
196 	{
197 		auto __p = gtk_paper_size_new_from_ipp(Str.toStringz(ippName), width, height);
198 
199 		if(__p is null)
200 		{
201 			throw new ConstructionException("null returned by new_from_ipp");
202 		}
203 
204 		this(cast(GtkPaperSize*) __p);
205 	}
206 
207 	/**
208 	 * Reads a paper size from the group @group_name in the key file
209 	 * @key_file.
210 	 *
211 	 * Params:
212 	 *     keyFile = the `GKeyFile` to retrieve the papersize from
213 	 *     groupName = the name of the group in the key file to read,
214 	 *         or %NULL to read the first group
215 	 *
216 	 * Returns: a new `GtkPaperSize` object with the restored paper size
217 	 *
218 	 * Throws: GException on failure.
219 	 * Throws: ConstructionException GTK+ fails to create the object.
220 	 */
221 	public this(KeyFile keyFile, string groupName)
222 	{
223 		GError* err = null;
224 
225 		auto __p = gtk_paper_size_new_from_key_file((keyFile is null) ? null : keyFile.getKeyFileStruct(), Str.toStringz(groupName), &err);
226 
227 		if (err !is null)
228 		{
229 			throw new GException( new ErrorG(err) );
230 		}
231 
232 		if(__p is null)
233 		{
234 			throw new ConstructionException("null returned by new_from_key_file");
235 		}
236 
237 		this(cast(GtkPaperSize*) __p);
238 	}
239 
240 	/**
241 	 * Creates a new `GtkPaperSize` object by using
242 	 * PPD information.
243 	 *
244 	 * If @ppd_name is not a recognized PPD paper name,
245 	 * @ppd_display_name, @width and @height are used to
246 	 * construct a custom `GtkPaperSize` object.
247 	 *
248 	 * Params:
249 	 *     ppdName = a PPD paper name
250 	 *     ppdDisplayName = the corresponding human-readable name
251 	 *     width = the paper width, in points
252 	 *     height = the paper height in points
253 	 *
254 	 * Returns: a new `GtkPaperSize`, use [method@Gtk.PaperSize.free]
255 	 *     to free it
256 	 *
257 	 * Throws: ConstructionException GTK+ fails to create the object.
258 	 */
259 	public this(string ppdName, string ppdDisplayName, double width, double height)
260 	{
261 		auto __p = gtk_paper_size_new_from_ppd(Str.toStringz(ppdName), Str.toStringz(ppdDisplayName), width, height);
262 
263 		if(__p is null)
264 		{
265 			throw new ConstructionException("null returned by new_from_ppd");
266 		}
267 
268 		this(cast(GtkPaperSize*) __p);
269 	}
270 
271 	/**
272 	 * Copies an existing `GtkPaperSize`.
273 	 *
274 	 * Returns: a copy of @other
275 	 */
276 	public PaperSize copy()
277 	{
278 		auto __p = gtk_paper_size_copy(gtkPaperSize);
279 
280 		if(__p is null)
281 		{
282 			return null;
283 		}
284 
285 		return ObjectG.getDObject!(PaperSize)(cast(GtkPaperSize*) __p, true);
286 	}
287 
288 	/**
289 	 * Free the given `GtkPaperSize` object.
290 	 */
291 	public void free()
292 	{
293 		gtk_paper_size_free(gtkPaperSize);
294 		ownedRef = false;
295 	}
296 
297 	/**
298 	 * Gets the default bottom margin for the `GtkPaperSize`.
299 	 *
300 	 * Params:
301 	 *     unit = the unit for the return value, not %GTK_UNIT_NONE
302 	 *
303 	 * Returns: the default bottom margin
304 	 */
305 	public double getDefaultBottomMargin(GtkUnit unit)
306 	{
307 		return gtk_paper_size_get_default_bottom_margin(gtkPaperSize, unit);
308 	}
309 
310 	/**
311 	 * Gets the default left margin for the `GtkPaperSize`.
312 	 *
313 	 * Params:
314 	 *     unit = the unit for the return value, not %GTK_UNIT_NONE
315 	 *
316 	 * Returns: the default left margin
317 	 */
318 	public double getDefaultLeftMargin(GtkUnit unit)
319 	{
320 		return gtk_paper_size_get_default_left_margin(gtkPaperSize, unit);
321 	}
322 
323 	/**
324 	 * Gets the default right margin for the `GtkPaperSize`.
325 	 *
326 	 * Params:
327 	 *     unit = the unit for the return value, not %GTK_UNIT_NONE
328 	 *
329 	 * Returns: the default right margin
330 	 */
331 	public double getDefaultRightMargin(GtkUnit unit)
332 	{
333 		return gtk_paper_size_get_default_right_margin(gtkPaperSize, unit);
334 	}
335 
336 	/**
337 	 * Gets the default top margin for the `GtkPaperSize`.
338 	 *
339 	 * Params:
340 	 *     unit = the unit for the return value, not %GTK_UNIT_NONE
341 	 *
342 	 * Returns: the default top margin
343 	 */
344 	public double getDefaultTopMargin(GtkUnit unit)
345 	{
346 		return gtk_paper_size_get_default_top_margin(gtkPaperSize, unit);
347 	}
348 
349 	/**
350 	 * Gets the human-readable name of the `GtkPaperSize`.
351 	 *
352 	 * Returns: the human-readable name of @size
353 	 */
354 	public string getDisplayName()
355 	{
356 		return Str.toString(gtk_paper_size_get_display_name(gtkPaperSize));
357 	}
358 
359 	/**
360 	 * Gets the paper height of the `GtkPaperSize`, in
361 	 * units of @unit.
362 	 *
363 	 * Params:
364 	 *     unit = the unit for the return value, not %GTK_UNIT_NONE
365 	 *
366 	 * Returns: the paper height
367 	 */
368 	public double getHeight(GtkUnit unit)
369 	{
370 		return gtk_paper_size_get_height(gtkPaperSize, unit);
371 	}
372 
373 	/**
374 	 * Gets the name of the `GtkPaperSize`.
375 	 *
376 	 * Returns: the name of @size
377 	 */
378 	public string getName()
379 	{
380 		return Str.toString(gtk_paper_size_get_name(gtkPaperSize));
381 	}
382 
383 	/**
384 	 * Gets the PPD name of the `GtkPaperSize`, which
385 	 * may be %NULL.
386 	 *
387 	 * Returns: the PPD name of @size
388 	 */
389 	public string getPpdName()
390 	{
391 		return Str.toString(gtk_paper_size_get_ppd_name(gtkPaperSize));
392 	}
393 
394 	/**
395 	 * Gets the paper width of the `GtkPaperSize`, in
396 	 * units of @unit.
397 	 *
398 	 * Params:
399 	 *     unit = the unit for the return value, not %GTK_UNIT_NONE
400 	 *
401 	 * Returns: the paper width
402 	 */
403 	public double getWidth(GtkUnit unit)
404 	{
405 		return gtk_paper_size_get_width(gtkPaperSize, unit);
406 	}
407 
408 	/**
409 	 * Returns %TRUE if @size is not a standard paper size.
410 	 *
411 	 * Returns: whether @size is a custom paper size.
412 	 */
413 	public bool isCustom()
414 	{
415 		return gtk_paper_size_is_custom(gtkPaperSize) != 0;
416 	}
417 
418 	/**
419 	 * Compares two `GtkPaperSize` objects.
420 	 *
421 	 * Params:
422 	 *     size2 = another `GtkPaperSize` object
423 	 *
424 	 * Returns: %TRUE, if @size1 and @size2
425 	 *     represent the same paper size
426 	 */
427 	public bool isEqual(PaperSize size2)
428 	{
429 		return gtk_paper_size_is_equal(gtkPaperSize, (size2 is null) ? null : size2.getPaperSizeStruct()) != 0;
430 	}
431 
432 	/**
433 	 * Returns %TRUE if @size is an IPP standard paper size.
434 	 *
435 	 * Returns: whether @size is not an IPP custom paper size.
436 	 */
437 	public bool isIpp()
438 	{
439 		return gtk_paper_size_is_ipp(gtkPaperSize) != 0;
440 	}
441 
442 	/**
443 	 * Changes the dimensions of a @size to @width x @height.
444 	 *
445 	 * Params:
446 	 *     width = the new width in units of @unit
447 	 *     height = the new height in units of @unit
448 	 *     unit = the unit for @width and @height
449 	 */
450 	public void setSize(double width, double height, GtkUnit unit)
451 	{
452 		gtk_paper_size_set_size(gtkPaperSize, width, height, unit);
453 	}
454 
455 	/**
456 	 * Serialize a paper size to an `a{sv}` variant.
457 	 *
458 	 * Returns: a new, floating, `GVariant`
459 	 */
460 	public Variant toGvariant()
461 	{
462 		auto __p = gtk_paper_size_to_gvariant(gtkPaperSize);
463 
464 		if(__p is null)
465 		{
466 			return null;
467 		}
468 
469 		return new Variant(cast(GVariant*) __p);
470 	}
471 
472 	/**
473 	 * This function adds the paper size from @size to @key_file.
474 	 *
475 	 * Params:
476 	 *     keyFile = the `GKeyFile` to save the paper size to
477 	 *     groupName = the group to add the settings to in @key_file
478 	 */
479 	public void toKeyFile(KeyFile keyFile, string groupName)
480 	{
481 		gtk_paper_size_to_key_file(gtkPaperSize, (keyFile is null) ? null : keyFile.getKeyFileStruct(), Str.toStringz(groupName));
482 	}
483 
484 	/**
485 	 * Returns the name of the default paper size, which
486 	 * depends on the current locale.
487 	 *
488 	 * Returns: the name of the default paper size. The string
489 	 *     is owned by GTK and should not be modified.
490 	 */
491 	public static string getDefault()
492 	{
493 		return Str.toString(gtk_paper_size_get_default());
494 	}
495 
496 	/**
497 	 * Creates a list of known paper sizes.
498 	 *
499 	 * Params:
500 	 *     includeCustom = whether to include custom paper sizes
501 	 *         as defined in the page setup dialog
502 	 *
503 	 * Returns: a newly allocated list of newly
504 	 *     allocated `GtkPaperSize` objects
505 	 */
506 	public static ListG getPaperSizes(bool includeCustom)
507 	{
508 		auto __p = gtk_paper_size_get_paper_sizes(includeCustom);
509 
510 		if(__p is null)
511 		{
512 			return null;
513 		}
514 
515 		return new ListG(cast(GList*) __p, true);
516 	}
517 }